<%-- 
  -- Body New para Customer
  --
  -- @author pablo.tortorella
--%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/struts-html-el-1.2.8.tld" prefix="html-el"%>
<%@ taglib uri="/WEB-INF/struts-logic-el-1.2.8.tld" prefix="logic-el"%>
<%@ taglib uri="/WEB-INF/security.tld" prefix="security" %>

<%@ taglib uri="http://struts.apache.org/tags-bean-el" prefix="bean2"%>

<script src="<html:rewrite page='/protected/script/util.js'/>" type="text/javascript"></script>

<%-- Para EXT --%>
<link rel="stylesheet" type="text/css" href="<html:rewrite page='/protected/script/ext-1.1.1/resources/css/ext-all.css'/>" />

<script src="<html:rewrite page='/protected/script/ext-1.1.1/adapter/ext/ext-base.js'/>" type="text/javascript"></script>
<script src="<html:rewrite page='/protected/script/ext-1.1.1/ext-all.js'/>" type="text/javascript"></script>

<link rel="stylesheet" type="text/css" href="<html:rewrite page='/protected/style/dragdrop.css'/>" id="styleFile"/>

<%-- prototype esta en el main layout --%>
<script src="<html:rewrite page='/protected/script/scriptaculous/scriptaculous.js'/>" type="text/javascript"></script>

<script type="text/javascript">
    /** Crea un cliente */
    function createCustomer() {
        if (!validate()) {
			return;
		}
        var nameObj = $("createNameId");
        var corporateNameObj = $("createCorporateNameId");
        var documentObj = $("createDocumentId");
        var termsObj = $("createTermsId");
        var termsObject = $("termsId");
        var emailObj = $("createEmailId");
        var phoneObj = $("createPhoneId");
        var mobileObj = $("createMobileId");
        var addressStreetObj = $("createAddressStreetId");
        var addressNumberObj = $("createAddressNumberId");
        var addressFloorObj = $("createAddressFloorId");
        var addressRoomObj = $("createAddressRoomId");
        var addressZipCodeObj = $("createAddressZipCodeId");
        var addressCityObj = $("createAddressCityId");
        var addressTownObj = $("createAddressTownId");
        var contactObj = $("createContactId");
        
        nameObj.value = $("nameId").value;
        corporateNameObj.value = $("corporateNameId").value;
        documentObj.value = $("documentId").value;
        phoneObj.value = $("phoneId").value;
        mobileObj.value = $("mobileId").value;
        emailObj.value = $("emailId").value;
		termsObj.value = termsObject.options[termsObject.selectedIndex].value;
        addressStreetObj.value = $("addressStreetId").value;
        addressNumberObj.value = $("addressNumberId").value;
        addressFloorObj.value = $("addressFloorId").value;
        addressRoomObj.value = $("addressRoomId").value;
        addressZipCodeObj.value = $("addressZipCodeId").value;
        addressCityObj.value = $("addressCityId").value;
        addressTownObj.value = $("addressTownId").value;
        contactObj.value = $("contactId").value;

        var form = $("createCustomerFormId");
        form.submit();
    }
    
    function validate() {
    	if (Util.valid.isBlank($("nameId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar el nombre. ');
            $("nameId").focus();
            return false;
        }
		if (Util.valid.isBlank($("corporateNameId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar la raz&oacute;n social. ');
            $("corporateNameId").focus();
            return false;
        }
        if (Util.valid.isBlank($("documentId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar el documento. ');
            $("documentId").focus();
            return false;
        }
        if (Util.valid.isBlank($("addressStreetId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar la calle. ');
            $("addressStreetId").focus();
            return false;
        }
        if (Util.valid.isBlank($("addressNumberId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar el numero. ');
            $("addressNumberId").focus();
            return false;
        }
        if (Util.valid.isBlank($("addressCityId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar la ciudad. ');
            $("addressCityId").focus();
            return false;
        }
        if (Util.valid.isBlank($("addressTownId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar la localidad. ');
            $("addressTownId").focus();
            return false;
        }
        return true;
    }
</script>

<div class="errors">
    <html:errors />
</div>

<%-- El ID del form NO debe ser modificado. Se usa desde el menu --%>
<html:form action="/protected/showNewCustomer" styleId="customerFormId">

    <h2>Alta de cliente</h2>
    
    <div class="customerEdit">
        <table class="tableData" cellspacing="0">
            <tr>
                <td class="tableDataTitle">
                    Nombre*
                </td>
                <td class="tableDataValue">
                    <html:text property="name" styleId="nameId" size="45" maxlength="45" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Raz&oacute;n Social*
                </td>
                <td class="tableDataValue">
                    <html:text property="corporateName" styleId="corporateNameId" value="" size="50" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Documento* (CUIT/CUIL/DNI)
                </td>
                <td class="tableDataValue">
                    <html:text property="document" styleId="documentId" value="" size="14" maxlength="14" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Condici&oacute;n Impositiva
                </td>
                <td class="tableDataValue">
                   	<html:select property="termTypeSelected" styleClass="allSelects" styleId="termsId">
                        <html:optionsCollection property="termTypeCollection"/>
                    </html:select>
                </td>
            </tr>
			<tr>
                <td class="tableDataTitle">
                    Tel&eacute;fono
                </td>
                <td class="tableDataValue">
                    <html:text property="phone" styleId="phoneId" value="" size="25" maxlength="25" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Tel. Celular
                </td>
                <td class="tableDataValue">
                    <html:text property="mobile" styleId="mobileId" value="" size="25" maxlength="25" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Email
                </td>
                <td class="tableDataValue">
                    <html:text property="email" styleId="emailId" value="" size="50" maxlength="75" />
                </td>
            </tr>
            </tr><td class="tableDataTitle"></td><td class="tableDataValue"></td><tr>
            <tr>
           		<td class="tableDataTitle">
                    Direcci&oacute;n
                </td>
                <td class="tableDataValue">
               	 <table>
	                	<tr>
		                	<td>
	                    		Calle*
	                    	</td>
	                		<td>
	                    		<html:text property="addressStreet" name="customerForm" styleId="addressStreetId" />
	                    	</td>
                    	</tr>
                    	<tr>
		                	<td>
	                    		N&uacute;mero*
	                    	</td>
	                		<td>
								<html:text property="addressNumber" name="customerForm" styleId="addressNumberId" />
	                    	</td>
                    	</tr>
                    	<tr>
		                	<td>
	                    		Piso
	                    	</td>
	                		<td>
								<html:text property="addressFloor" name="customerForm" styleId="addressFloorId" />
	                    	</td>
                    	</tr>
                    	<tr>
		                	<td>
	                    		Departamento
	                    	</td>
	                		<td>
								<html:text property="addressRoom" name="customerForm" styleId="addressRoomId" />
	                    	</td>
                    	</tr>
                    	<tr>
		                	<td>
	                    		C&oacute;digo Postal
	                    	</td>
	                		<td>
								<html:text property="addressZipCode" name="customerForm" styleId="addressZipCodeId" size="8" maxlength="8" />
	                    	</td>
                    	</tr>
                    	<tr>
		                	<td>
	                    		Ciudad*
	                    	</td>
	                		<td>
								<html:text property="addressCity" name="customerForm" styleId="addressCityId" />
	                    	</td>
                    	</tr>
                    	<tr>
		                	<td>
	                    		Localidad*
	                    	</td>
	                		<td>
								<html:text property="addressTown" name="customerForm" styleId="addressTownId" />
	                    	</td>
                    	</tr>
                    </table>
                </td>
            </tr>
            </tr><td class="tableDataTitle"></td><td class="tableDataValue"></td><tr>
            <tr>
            	<td class="tableDataTitle">
            		Contacto
            	</td>
        		<td class="tableDataValue">
					<html:text property="contact" name="customerForm" value="" styleId="contactId" size="50" maxlength="75" />
            	</td>
        	</tr>
          </table>
    
    	<br/>
        <div id="clear"></div>
    	<p class="mensajeCamposObligatorios">Los campos marcados con un asterisco (*) son obligatorios.</p>
    	<div id="clear"></div>
    
        <%-- No se valida seguridad ya que SOLO entran aca los administradores --%>
        <div class="panelButton">
            <input type="button" value="Guardar" onclick="createCustomer();" title="Guarda el cliente..." class="button">
        </div>  
    
    </div>

</html:form>

<%-- Inyectados por Javascript --%>
<div id="createDivId" class="hideClass">
    <html:form action="/protected/createCustomer" styleId="createCustomerFormId">
        <html:hidden property="name" value="" styleId="createNameId" />
        <html:hidden property="corporateName" value="" styleId="createCorporateNameId" />
        <html:hidden property="document" value="" styleId="createDocumentId" />
        <html:hidden property="email" value="" styleId="createEmailId" />
        <html:hidden property="phone" value="" styleId="createPhoneId" />
        <html:hidden property="mobile" value="" styleId="createMobileId" />
        <html:hidden property="terms" value="" styleId="createTermsId" />
        <html:hidden property="addressStreet" value="" styleId="createAddressStreetId" />
        <html:hidden property="addressNumber" value="" styleId="createAddressNumberId" />
        <html:hidden property="addressFloor" value="" styleId="createAddressFloorId" />
        <html:hidden property="addressRoom" value="" styleId="createAddressRoomId" />
        <html:hidden property="addressZipCode" value="" styleId="createAddressZipCodeId" />
        <html:hidden property="addressCity" value="" styleId="createAddressCityId" />
        <html:hidden property="addressTown" value="" styleId="createAddressTownId" />
        <html:hidden property="contact" value="" styleId="createContactId" />
    </html:form>
</div>
